package com.effort.com.effort.excle.core.util;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 高复用服务器端响应对象
 * 
 * @author trekxu
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public final class ServerResponse {

	// 返回的消息
	private String msg;

	// 是否成功
	private boolean success;

	// 响应的数据
	private Object data;

	/**
	 * 操作成功的响应
	 * 
	 * @return
	 */
	public static ServerResponse ok() {
		return ServerResponse.builder().success(true).build();
	}

	/**
	 * 附带提示信息的成功响应
	 * 
	 * @param msg
	 * @return
	 */
	public static ServerResponse ok(String msg) {
		return ServerResponse.builder().success(true).msg(msg).build();
	}

	/**
	 * 附带数据的响应对象
	 * 
	 * @param data
	 * @return
	 */
	public static ServerResponse ok(Object data) {
		return ServerResponse.builder().success(true).data(data).build();
	}

	/**
	 * 附带数据和消息的响应对象
	 * 
	 * @param data
	 * @return
	 */
	public static ServerResponse ok(String msg, Object data) {
		return ServerResponse.builder().success(true).msg(msg).data(data).build();
	}

	/**
	 * 失败的操作响应
	 * 
	 * @return
	 */
	public static ServerResponse fail() {
		return ServerResponse.builder().success(false).build();
	}

	/**
	 * 附带失败信息的响应
	 */
	public static ServerResponse fail(String msg) {
		return ServerResponse.builder().success(false).msg(msg).build();
	}
}
